﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Behavior.Interfaces;
using Microsoft.Xna.Framework;
using Twodi.Aspect.Interfaces;
using Twodi.Input;

namespace Twodi.Behavior.Implemented
{
    /// <summary>
    /// Comportamento responsavel por atualizar e renderizar componentes do container.
    /// </summary>
    public class ContainerBehavior : AbstractBehavior<IContainerAspect>
    {
        /// <summary>
        /// Construtor padrão.
        /// </summary>
        /// <param name="component">Componente a ser manipulado pelo comportamento.</param>
        public ContainerBehavior(IContainerAspect component)
            : base(component)
        {

        }

        /// <summary>
        /// Inicializar todos componentes dentro do container.
        /// </summary>
        public override void Initialize()
        {
            for (int i = 0; i < this.Component.ContainerProperties.Components.Count; i++)
            {
                IGameComponent component = this.Component.ContainerProperties.Components[i];
                if (component != null)
                {
                    component.Initialize();
                }
            }
        }

        /// <summary>
        /// Atualizar todos componentes ativos dentro do container.
        /// </summary>
        /// <param name="gameTime">Tempo do jogo.</param>
        public override void Update(GameTime gameTime)
        {
            for (int i = 0; i < this.Component.ContainerProperties.Components.Count; i++)
            {
                IUpdateable component = this.Component.ContainerProperties.Components[i] as IUpdateable;
                if (component != null)
                {
                    if (component.Enabled) component.Update(gameTime);
                }
            }
        }

        /// <summary>
        /// Renderizar todos componentes visiveis dentro do container.
        /// </summary>
        /// <param name="gameTime">Tempo do jogo.</param>
        public override void Draw(GameTime gameTime)
        {
            for (int i = 0; i < this.Component.ContainerProperties.Components.Count; i++)
            {
                IDrawable component = this.Component.ContainerProperties.Components[i] as IDrawable;
                if (component != null)
                {
                    if (component.Visible) component.Draw(gameTime);
                }
            }
        }

        public override bool Handle(KeyboardInput input)
        {
            throw new NotImplementedException();
        }

        public override bool Handle(MouseInput input)
        {
            throw new NotImplementedException();
        }
    }
}
